1. /* simncvdc.cpp by K.Tsuru */
  2. // function ID = 413 BRADIX
  3. /***************************************************************************
  4. SInteger class
  5. It provides a normal radix conversion.
  6. BRADIX ---> DRADIX
  7. The processing time is proportional to the square of the number of figures.
  8. ***************************************************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. SLong SInteger::NConvToDec() const{
  13. SLong result;
  14. uint szD = Head()+1u;
  15. if(szD <= 2u){ //under two figures including zero
  16. long v = (long)figure(1)*BRADIX + (long)figure(0);
  17. if(Sign() < 0) v = -v;
  18. result.SetLong(v);
  19. return result;
  20. }
  21. SInteger a(*this);
  22. uint szB = uint( (double)szD*log10((double)BRADIX)/DFIGURES )+ 1u; // ver.2.17
  23. result.FigureAlloc(szB, -1);
  24. fType* rv = result.figure.Elements();
  25. if(a.Sign() < 0) a.ChangeSign();
  26. register uint j = 0;
  27. while(a.Sign()){
  28. rv[j++] = (fType)IsDiv(a, DRADIX, a); //a /= DRADIX; rv[j]=a%DRADIX;
  29. }
  30. #ifndef NDEBUG
  31. result.figure(j-1);
  32. #endif
  33. result.figure.clear(j);
  34. result.aHead = j-1; // j >= 1
  35. j = 0;
  36. while(rv[j] == 0) j++;
  37. result.aTail = j;
  38. result.SetSign( Sign() );
  39. result.CutDown(result.POP);
  40. if( 2u*(result.aHead+1) <= result.figure.size() ) result.DoCutDown();
  41. return result;
  42. }

simncvdc.cpp : last modifiled at 2017/03/13 14:32:00(1,302 bytes)
created at 2016/04/25 14:53:17
The creation time of this html file is 2017/10/25 11:09:45 (Wed Oct 25 11:09:45 2017).